home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / sbin / apxs.z / apxs
Text File  |  2002-07-08  |  21KB  |  717 lines

  1. #!/usr/sbin/perl -w
  2. # ====================================================================
  3. # The Apache Software License, Version 1.1
  4. #
  5. # Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  6. # reserved.
  7. #
  8. # Redistribution and use in source and binary forms, with or without
  9. # modification, are permitted provided that the following conditions
  10. # are met:
  11. #
  12. # 1. Redistributions of source code must retain the above copyright
  13. #    notice, this list of conditions and the following disclaimer.
  14. #
  15. # 2. Redistributions in binary form must reproduce the above copyright
  16. #    notice, this list of conditions and the following disclaimer in
  17. #    the documentation and/or other materials provided with the
  18. #    distribution.
  19. #
  20. # 3. The end-user documentation included with the redistribution,
  21. #    if any, must include the following acknowledgment:
  22. #       "This product includes software developed by the
  23. #        Apache Software Foundation (http://www.apache.org/)."
  24. #    Alternately, this acknowledgment may appear in the software itself,
  25. #    if and wherever such third-party acknowledgments normally appear.
  26. #
  27. # 4. The names "Apache" and "Apache Software Foundation" must
  28. #    not be used to endorse or promote products derived from this
  29. #    software without prior written permission. For written
  30. #    permission, please contact apache@apache.org.
  31. #
  32. # 5. Products derived from this software may not be called "Apache",
  33. #    nor may "Apache" appear in their name, without prior written
  34. #    permission of the Apache Software Foundation.
  35. #
  36. # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. # DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. # SUCH DAMAGE.
  48. # ====================================================================
  49. #
  50. # This software consists of voluntary contributions made by many
  51. # individuals on behalf of the Apache Software Foundation.  For more
  52. # information on the Apache Software Foundation, please see
  53. # <http://www.apache.org/>.
  54. #
  55.  
  56. require 5.003;
  57. use strict;
  58. package apxs;
  59.  
  60. ##
  61. ##  Configuration
  62. ##
  63.  
  64. my %config_vars = ();
  65.  
  66. my $installbuilddir = "/usr/freeware/apache2/build";
  67. get_config_vars("$installbuilddir/config_vars.mk",\%config_vars);
  68.  
  69. # read the configuration variables once
  70.  
  71. my $prefix         = get_vars("prefix");
  72. my $CFG_PREFIX     = $prefix;
  73. my $exec_prefix    = get_vars("exec_prefix");
  74. my $datadir        = get_vars("datadir");
  75. my $localstatedir  = get_vars("localstatedir");
  76. my $CFG_TARGET     = get_vars("progname");
  77. my $CFG_SYSCONFDIR = get_vars("sysconfdir");
  78. my $CFG_CFLAGS     = join ' ', map { get_vars($_) }
  79.   qw(SHLTCFLAGS CFLAGS NOTEST_CPPFLAGS EXTRA_CPPFLAGS EXTRA_CFLAGS);
  80. my $includedir     = get_vars("includedir");
  81. my $CFG_INCLUDEDIR = eval qq("$includedir");
  82. my $CFG_CC         = get_vars("CC");
  83. my $libexecdir     = get_vars("libexecdir");
  84. my $CFG_LIBEXECDIR = eval qq("$libexecdir");
  85. my $sbindir        = get_vars("sbindir");
  86. my $CFG_SBINDIR    = eval qq("$sbindir");
  87. my $ltflags        = $ENV{'LTFLAGS'};
  88. $ltflags or $ltflags = "--silent";
  89.  
  90. my %internal_vars = map {$_ => 1}
  91.     qw(TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
  92.        PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR);
  93.  
  94. ##
  95. ##  parse argument line
  96. ##
  97.  
  98. #   defaults for parameters
  99. my $opt_n = '';
  100. my $opt_g = '';
  101. my $opt_c = 0;
  102. my $opt_o = '';
  103. my @opt_D = ();
  104. my @opt_I = ();
  105. my @opt_L = ();
  106. my @opt_l = ();
  107. my @opt_W = ();
  108. my @opt_S = ();
  109. my $opt_e = 0;
  110. my $opt_i = 0;
  111. my $opt_a = 0;
  112. my $opt_A = 0;
  113. my $opt_q = 0;
  114. my $opt_h = 0;
  115.  
  116. #   this subroutine is derived from Perl's getopts.pl with the enhancement of
  117. #   the "+" metacharacter at the format string to allow a list to be built by
  118. #   subsequent occurrences of the same option.
  119. sub Getopts {
  120.     my ($argumentative, @ARGV) = @_;
  121.     my $errs = 0;
  122.     local $_;
  123.     local $[ = 0;
  124.  
  125.     my @args = split / */, $argumentative;
  126.     while (@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
  127.         my ($first, $rest) = ($1,$2);
  128.         if ($_ =~ m|^--$|) {
  129.             shift @ARGV;
  130.             last;
  131.         }
  132.         my $pos = index($argumentative,$first);
  133.         if ($pos >= $[) {
  134.             if ($args[$pos+1] eq ':') {
  135.                 shift @ARGV;
  136.                 if ($rest eq '') {
  137.                     unless (@ARGV) {
  138.                         error("Incomplete option: $first (needs an argument)");
  139.                         $errs++;
  140.                     }
  141.                     $rest = shift(@ARGV);
  142.                 }
  143.                 eval "\$opt_$first = \$rest;";
  144.             }
  145.             elsif ($args[$pos+1] eq '+') {
  146.                 shift @ARGV;
  147.                 if ($rest eq '') {
  148.                     unless (@ARGV) {
  149.                         error("Incomplete option: $first (needs an argument)");
  150.                         $errs++;
  151.                     }
  152.                     $rest = shift(@ARGV);
  153.                 }
  154.                 eval "push(\@opt_$first, \$rest);";
  155.             }
  156.             else {
  157.                 eval "\$opt_$first = 1";
  158.                 if ($rest eq '') {
  159.                     shift(@ARGV);
  160.                 }
  161.                 else {
  162.                     $ARGV[0] = "-$rest";
  163.                 }
  164.             }
  165.         }
  166.         else {
  167.             error("Unknown option: $first");
  168.             $errs++;
  169.             if ($rest ne '') {
  170.                 $ARGV[0] = "-$rest";
  171.             }
  172.             else {
  173.                 shift(@ARGV);
  174.             }
  175.         }
  176.     }
  177.     return ($errs == 0, @ARGV);
  178. }
  179.  
  180. sub usage {
  181.     print STDERR "Usage: apxs -g [-S <var>=<val>] -n <modname>\n";
  182.     print STDERR "       apxs -q [-S <var>=<val>] <query> ...\n";
  183.     print STDERR "       apxs -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]\n";
  184.     print STDERR "               [-I <incdir>] [-L <libdir>] [-l <libname>] [-Wc,<flags>]\n";
  185.     print STDERR "               [-Wl,<flags>] <files> ...\n";
  186.     print STDERR "       apxs -i [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
  187.     print STDERR "       apxs -e [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
  188.     exit(1);
  189. }
  190.  
  191. #   option handling
  192. my $rc;
  193. ($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaA", @ARGV);
  194. &usage if ($rc == 0);
  195. &usage if ($#ARGV == -1 and not $opt_g);
  196. &usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c and not $opt_e);
  197.  
  198. #   argument handling
  199. my @args = @ARGV;
  200. my $name = 'unknown';
  201. $name = $opt_n if ($opt_n ne '');
  202.  
  203. if (@opt_S) {
  204.     my ($opt_S);
  205.     foreach $opt_S (@opt_S) {
  206.     if ($opt_S =~ m/^([^=]+)=(.*)$/) {
  207.         my ($var) = $1;
  208.         my ($val) = $2;
  209.         my $oldval = eval "\$CFG_$var";
  210.  
  211.         unless ($var and $oldval) {
  212.         print STDERR "apxs:Error: no config variable $var\n";
  213.         &usage;
  214.         }
  215.  
  216.         eval "\$CFG_${var}=\"${val}\"";
  217.     } else {
  218.         print STDERR "apxs:Error: malformatted -S option\n";
  219.         &usage;
  220.     }    
  221.     }
  222. }
  223.  
  224. ##
  225. ##  Initial shared object support check
  226. ##
  227. my $httpd = get_vars("sbindir") . "/" . get_vars("progname");
  228. $httpd = eval qq("$httpd");
  229. $httpd = eval qq("$httpd");
  230. my $envvars = get_vars("sbindir") . "/envvars";
  231. $envvars = eval qq("$envvars");
  232. $envvars = eval qq("$envvars");
  233.  
  234. #allow apxs to be run from the source tree, before installation
  235. if ($0 =~ m:support/apxs$:) {
  236.     ($httpd = $0) =~ s:support/apxs$::;
  237. }
  238.  
  239. unless (-x "$httpd") {
  240.     error("$httpd not found or not executable");
  241.     exit 1;
  242. }
  243.  
  244. unless (grep /mod_so/, `. $envvars && $httpd -l`) {
  245.     error("Sorry, no shared object support for Apache");
  246.     error("available under your platform. Make sure");
  247.     error("the Apache module mod_so is compiled into");
  248.     error("your server binary `$httpd'.");
  249.     exit 1;
  250. }
  251.  
  252. sub get_config_vars{
  253.     my ($file, $rh_config) = @_;
  254.  
  255.     open IN, $file or die "cannot open $file: $!";
  256.     while (<IN>){
  257.         if (/^\s*(.*?)\s*=\s*(.*)$/){
  258.             $rh_config->{$1} = $2;
  259.         }
  260.     }
  261.     close IN;
  262. }
  263.  
  264. sub get_vars {
  265.     my $result = '';
  266.     my $ok = 0;
  267.     my $arg;
  268.     foreach $arg (@_) {
  269.         if (exists $config_vars{$arg} or exists $config_vars{lc $arg}) {
  270.             my $val = exists $config_vars{$arg}
  271.                 ? $config_vars{$arg}
  272.                 : $config_vars{lc $arg};
  273.             $val =~ s/[()]//g;
  274.             $result .= eval "qq($val)" if defined $val;
  275.             $result .= ";;";
  276.             $ok = 1;
  277.         }
  278.         if (not $ok) {
  279.             if (exists $internal_vars{$arg} or exists $internal_vars{lc $arg}) {
  280.                 my $val = exists $internal_vars{$arg} ? $arg : lc $arg;
  281.                 $val = eval "\$CFG_$val";
  282.                 $result .= eval "qq($val)" if defined $val;
  283.                 $result .= ";;";
  284.                 $ok = 1;
  285.             }
  286.             if (not $ok) {
  287.                 error("Invalid query string `$arg'");
  288.                 exit(1);
  289.             }
  290.         }
  291.     }
  292.     $result =~ s|;;$||;
  293.     $result =~ s|:| |;
  294.     return $result;
  295. }
  296.  
  297. ##
  298. ##  Operation
  299. ##
  300.  
  301. #   helper function for executing a list of
  302. #   system command with return code checks
  303. sub execute_cmds {
  304.     my (@cmds) = @_;
  305.     my ($cmd, $rc);
  306.  
  307.     foreach $cmd (@cmds) {
  308.         notice($cmd);
  309.         $rc = system $cmd;
  310.         if ($rc) {
  311.             error(sprintf "Command failed with rc=%d\n", $rc << 8);
  312.             exit 1 ;
  313.         }
  314.     }
  315. }
  316.  
  317. if ($opt_g) {
  318.     ##
  319.     ##  SAMPLE MODULE SOURCE GENERATION
  320.     ##
  321.  
  322.     if (-d $name) {
  323.         error("Directory `$name' already exists. Remove first");
  324.         exit(1);
  325.     }
  326.  
  327.     my $data = join('', <DATA>);
  328.     $data =~ s|%NAME%|$name|sg;
  329.     $data =~ s|%TARGET%|$CFG_TARGET|sg;
  330.     $data =~ s|%PREFIX%|$prefix|sg;
  331.     $data =~ s|%INSTALLBUILDDIR%|$installbuilddir|sg;
  332.  
  333.     my ($mkf, $mods, $src) = ($data =~ m|^(.+)-=#=-\n(.+)-=#=-\n(.+)|s);
  334.  
  335.     notice("Creating [DIR]  $name");
  336.     system("mkdir $name");
  337.     notice("Creating [FILE] $name/Makefile");
  338.     open(FP, ">${name}/Makefile") || die;
  339.     print FP $mkf;
  340.     close(FP);
  341.     notice("Creating [FILE] $name/modules.mk");
  342.     open(FP, ">${name}/modules.mk") || die;
  343.     print FP $mods;
  344.     close(FP);
  345.     notice("Creating [FILE] $name/mod_$name.c");
  346.     open(FP, ">${name}/mod_${name}.c") || die;
  347.     print FP $src;
  348.     close(FP);
  349.     notice("Creating [FILE] $name/.deps");
  350.     system("touch ${name}/.deps");
  351.  
  352.     exit(0);
  353. }
  354.  
  355.  
  356. if ($opt_q) {
  357.     ##
  358.     ##  QUERY INFORMATION 
  359.     ##
  360.     my $result = get_vars(@args);
  361.     print "$result";
  362. }
  363.  
  364. if ($opt_c) {
  365.     ##
  366.     ##  SHARED OBJECT COMPILATION
  367.     ##
  368.  
  369.     #   split files into sources and objects
  370.     my @srcs = ();
  371.     my @objs = ();
  372.     my $f;
  373.     foreach $f (@args) {
  374.         if ($f =~ m|\.c$|) {
  375.             push(@srcs, $f);
  376.         }
  377.         else {
  378.             push(@objs, $f);
  379.         }
  380.     }
  381.  
  382.     #   determine output file
  383.     my $dso_file;
  384.     if ($opt_o eq '') {
  385.         if ($#srcs > -1) {
  386.             $dso_file = $srcs[0];
  387.             $dso_file =~ s|\.[^.]+$|.la|;
  388.         }
  389.         elsif ($#objs > -1) {
  390.             $dso_file = $objs[0];
  391.             $dso_file =~ s|\.[^.]+$|.la|;
  392.         }
  393.         else {
  394.             $dso_file = "mod_unknown.so";
  395.         }
  396.     }
  397.     else {
  398.         $dso_file = $opt_o;
  399.     }
  400.  
  401.     #   create compilation commands
  402.     my @cmds = ();
  403.     my $opt = '';
  404.     my ($opt_Wc, $opt_I, $opt_D);
  405.     foreach $opt_Wc (@opt_W) {
  406.         $opt .= "$1 " if ($opt_Wc =~ m|^\s*c,(.*)$|);
  407.     }
  408.     foreach $opt_I (@opt_I) {
  409.         $opt .= "-I$opt_I ";
  410.     }
  411.     foreach $opt_D (@opt_D) {
  412.         $opt .= "-D$opt_D ";
  413.     }
  414.     my $cflags = "$CFG_CFLAGS";
  415.     my $s;
  416.     my $mod;
  417.     foreach $s (@srcs) {
  418.         my $slo = $s;
  419.         $slo =~ s|\.c$|.slo|;
  420.         my $lo = $s;
  421.         $lo =~ s|\.c$|.lo|;
  422.         my $la = $s;
  423.         $la =~ s|\.c$|.la|;
  424.         my $o = $s;
  425.         $o =~ s|\.c$|.o|;
  426.         push(@cmds, "$installbuilddir/libtool $ltflags --mode=compile $CFG_CC $cflags -I$CFG_INCLUDEDIR $opt -c -o $lo $s && touch $slo");
  427.         unshift(@objs, $lo);
  428.     }
  429.  
  430.     #   create link command
  431.     my $o;
  432.     my $lo;    
  433.     foreach $o (@objs) {
  434.         $lo .= " $o";
  435.     }
  436.     my ($opt_Wl, $opt_L, $opt_l);
  437.     foreach $opt_Wl (@opt_W) {
  438.         if ($CFG_CC !~ m/gcc$/) {
  439.             $opt .= " $1" if ($opt_Wl =~ m|^\s*l,(.*)$|);
  440.         } else {
  441.             $opt .= " -W$opt_Wl";
  442.         }
  443.     }
  444.     foreach $opt_L (@opt_L) {
  445.         $opt .= " -L$opt_L";
  446.     }
  447.     foreach $opt_l (@opt_l) {
  448.         $opt .= " -l$opt_l";
  449.     }
  450.  
  451.     push(@cmds, "$installbuilddir/libtool $ltflags --mode=link $CFG_CC -o $dso_file -rpath $CFG_LIBEXECDIR -module -avoid-version $opt $lo");
  452.  
  453.     #   execute the commands
  454.     &execute_cmds(@cmds);
  455.  
  456.     #   allow one-step compilation and installation
  457.     if ($opt_i or $opt_e) {
  458.         @args = ( $dso_file );
  459.     }
  460. }
  461.  
  462. if ($opt_i or $opt_e) {
  463.     ##
  464.     ##  SHARED OBJECT INSTALLATION
  465.     ##
  466.  
  467.     #   determine installation commands
  468.     #   and corresponding LoadModule/AddModule directives
  469.     my @lmd = ();
  470.     my @amd = ();
  471.     my @cmds = ();
  472.     my $f;
  473.     foreach $f (@args) {
  474.         if ($f !~ m#(\.so$|\.la$)#) {
  475.             error("file $f is not a shared object");
  476.             exit(1);
  477.         }
  478.         my $t = $f;
  479.         $t =~ s|^.+/([^/]+)$|$1|;
  480.         $t =~ s|\.la$|\.so|;
  481.         if ($opt_i) {
  482.         push(@cmds, "$installbuilddir/instdso.sh SH_LIBTOOL='" .
  483.                  "$installbuilddir/libtool' $f $CFG_LIBEXECDIR");
  484.         push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
  485.         }
  486.  
  487.         #   determine module symbolname and filename
  488.         my $filename = '';
  489.         if ($name eq 'unknown') {
  490.             $name = '';
  491.             my $base = $f;
  492.             $base =~ s|\.[^.]+$||;
  493.             if (-f "$base.c") {
  494.                 open(FP, "<$base.c");
  495.                 my $content = join('', <FP>);
  496.                 close(FP);
  497.                 if ($content =~ m|.*module\s+(?:AP_MODULE_DECLARE_DATA\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
  498.                     $name = "$1";
  499.                     $filename = "$base.c";
  500.                     $filename =~ s|^[^/]+/||;
  501.                 }
  502.             }
  503.             if ($name eq '') {
  504.                 if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
  505.                     $name = "$1";
  506.                     $filename = $base;
  507.                     $filename =~ s|^[^/]+/||;
  508.                 }
  509.             }
  510.             if ($name eq '') {
  511.                 error("Sorry, cannot determine bootstrap symbol name");
  512.                 error("Please specify one with option `-n'");
  513.                 exit(1);
  514.             }
  515.         }
  516.         if ($filename eq '') {
  517.             $filename = "mod_${name}.c";
  518.         }
  519.         my $dir = $CFG_LIBEXECDIR;
  520.         $dir =~ s|^$CFG_PREFIX/?||;
  521.         $dir =~ s|(.)$|$1/|;
  522.     $t =~ s|\.la$|.so|;
  523.         push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
  524.         push(@amd, sprintf("AddModule %s", $filename));
  525.     }
  526.  
  527.     #   execute the commands
  528.     &execute_cmds(@cmds);
  529.  
  530.     #   activate module via LoadModule/AddModule directive
  531.     if ($opt_a or $opt_A) {
  532.         if (not -f "$CFG_SYSCONFDIR/$CFG_TARGET.conf") {
  533.             error("Config file $CFG_SYSCONFDIR/$CFG_TARGET.conf not found");
  534.             exit(1);
  535.         }
  536.  
  537.         open(FP, "<$CFG_SYSCONFDIR/$CFG_TARGET.conf") || die;
  538.         my $content = join('', <FP>);
  539.         close(FP);
  540.  
  541.         if ($content !~ m|\n#?\s*LoadModule\s+|) {
  542.             error("Activation failed for custom $CFG_SYSCONFDIR/$CFG_TARGET.conf file.");
  543.             error("At least one `LoadModule' directive already has to exist.");
  544.             exit(1);
  545.         }
  546.  
  547.         my $lmd;
  548.         my $c = '';
  549.         $c = '#' if ($opt_A);
  550.         foreach $lmd (@lmd) {
  551.             my $what = $opt_A ? "preparing" : "activating";
  552.             if ($content !~ m|\n#?\s*$lmd|) {
  553.                  $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|sg;
  554.             } else {
  555.                  $content =~ s|^(.*\n)#?\s*$lmd[^\n]*\n|$1$c$lmd\n|sg;
  556.             }
  557.             $lmd =~ m|LoadModule\s+(.+?)_module.*|;
  558.             notice("[$what module `$1' in $CFG_SYSCONFDIR/$CFG_TARGET.conf]");
  559.         }
  560.         my $amd;
  561.         foreach $amd (@amd) {
  562.             if ($content !~ m|\n#?\s*$amd|) {
  563.                  $content =~ s|^(.*\n#?\s*AddModule\s+[^\n]+\n)|$1$c$amd\n|sg;
  564.             } else {
  565.                  $content =~ s|^(.*\n)#?\s*$amd[^\n]*\n|$1$c$amd\n|sg;
  566.             }
  567.         }
  568.         if (@lmd or @amd) {
  569.             if (open(FP, ">$CFG_SYSCONFDIR/$CFG_TARGET.conf.new")) {
  570.                 print FP $content;
  571.                 close(FP);
  572.                 system("cp $CFG_SYSCONFDIR/$CFG_TARGET.conf $CFG_SYSCONFDIR/$CFG_TARGET.conf.bak && " .
  573.                        "cp $CFG_SYSCONFDIR/$CFG_TARGET.conf.new $CFG_SYSCONFDIR/$CFG_TARGET.conf && " .
  574.                        "rm $CFG_SYSCONFDIR/$CFG_TARGET.conf.new");
  575.             } else {
  576.                 notice("unable to open configuration file");
  577.             }
  578.     }
  579.     }
  580. }
  581.  
  582. sub error{
  583.     print STDERR "apxs:Error: $_[0].\n";
  584. }
  585.  
  586. sub notice{
  587.     print STDERR "$_[0]\n";
  588. }
  589.  
  590. ##EOF##
  591. __DATA__
  592. ##
  593. ##  Makefile -- Build procedure for sample %NAME% Apache module
  594. ##  Autogenerated via ``apxs -n %NAME% -g''.
  595. ##
  596.  
  597. builddir=.
  598. top_srcdir=%PREFIX%
  599. top_builddir=%PREFIX%
  600. include %INSTALLBUILDDIR%/special.mk
  601.  
  602. #   the used tools
  603. APXS=apxs
  604. APACHECTL=apachectl
  605.  
  606. #   additional defines, includes and libraries
  607. #DEF=-Dmy_define=my_value
  608. #INC=-Imy/include/dir
  609. #LIB=-Lmy/lib/dir -lmylib
  610.  
  611. #   the default target
  612. all: local-shared-build
  613.  
  614. #   install the shared object file into Apache 
  615. install: install-modules
  616.  
  617. #   cleanup
  618. clean:
  619.     -rm -f mod_%NAME%.o mod_%NAME%.lo mod_%NAME%.slo mod_%NAME%.la 
  620.  
  621. #   simple test
  622. test: reload
  623.     lynx -mime_header http://localhost/%NAME%
  624.  
  625. #   install and activate shared object by reloading Apache to
  626. #   force a reload of the shared object file
  627. reload: install restart
  628.  
  629. #   the general Apache start/restart/stop
  630. #   procedures
  631. start:
  632.     $(APACHECTL) start
  633. restart:
  634.     $(APACHECTL) restart
  635. stop:
  636.     $(APACHECTL) stop
  637.  
  638. -=#=-
  639. mod_%NAME%.la: mod_%NAME%.slo
  640.     $(SH_LINK) -rpath $(libexecdir) -module -avoid-version  mod_%NAME%.lo
  641. DISTCLEAN_TARGETS = modules.mk
  642. shared =  mod_%NAME%.la
  643. -=#=-
  644. /* 
  645. **  mod_%NAME%.c -- Apache sample %NAME% module
  646. **  [Autogenerated via ``apxs -n %NAME% -g'']
  647. **
  648. **  To play with this sample module first compile it into a
  649. **  DSO file and install it into Apache's modules directory 
  650. **  by running:
  651. **
  652. **    $ apxs -c -i mod_%NAME%.c
  653. **
  654. **  Then activate it in Apache's %TARGET%.conf file for instance
  655. **  for the URL /%NAME% in as follows:
  656. **
  657. **    #   %TARGET%.conf
  658. **    LoadModule %NAME%_module modules/mod_%NAME%.so
  659. **    <Location /%NAME%>
  660. **    SetHandler %NAME%
  661. **    </Location>
  662. **
  663. **  Then after restarting Apache via
  664. **
  665. **    $ apachectl restart
  666. **
  667. **  you immediately can request the URL /%NAME% and watch for the
  668. **  output of this module. This can be achieved for instance via:
  669. **
  670. **    $ lynx -mime_header http://localhost/%NAME% 
  671. **
  672. **  The output should be similar to the following one:
  673. **
  674. **    HTTP/1.1 200 OK
  675. **    Date: Tue, 31 Mar 1998 14:42:22 GMT
  676. **    Server: Apache/1.3.4 (Unix)
  677. **    Connection: close
  678. **    Content-Type: text/html
  679. **  
  680. **    The sample page from mod_%NAME%.c
  681. */ 
  682.  
  683. #include "httpd.h"
  684. #include "http_config.h"
  685. #include "http_protocol.h"
  686. #include "ap_config.h"
  687.  
  688. /* The sample content handler */
  689. static int %NAME%_handler(request_rec *r)
  690. {
  691.     if (strcmp(r->handler, "%NAME%")) {
  692.         return DECLINED;
  693.     }
  694.     r->content_type = "text/html";      
  695.  
  696.     if (!r->header_only)
  697.         ap_rputs("The sample page from mod_%NAME%.c\n", r);
  698.     return OK;
  699. }
  700.  
  701. static void %NAME%_register_hooks(apr_pool_t *p)
  702. {
  703.     ap_hook_handler(%NAME%_handler, NULL, NULL, APR_HOOK_MIDDLE);
  704. }
  705.  
  706. /* Dispatch list for API hooks */
  707. module AP_MODULE_DECLARE_DATA %NAME%_module = {
  708.     STANDARD20_MODULE_STUFF, 
  709.     NULL,                  /* create per-dir    config structures */
  710.     NULL,                  /* merge  per-dir    config structures */
  711.     NULL,                  /* create per-server config structures */
  712.     NULL,                  /* merge  per-server config structures */
  713.     NULL,                  /* table of config file commands       */
  714.     %NAME%_register_hooks  /* register hooks                      */
  715. };
  716.  
  717.